package com.tgr.shortLink.admin.common.config;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.Data;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 描述：MP自动填充时间数据
 * 作者：小陶不慌张
 * 文件：MyMetaObjectHandler
 * 日期：2023/12/24 23:51
 */
@Primary
@Component("myMetaObjectHandlerByAdmin")
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject){
        strictInsertFill(metaObject, "createTime", DateTime::new, Date.class);
        strictInsertFill(metaObject, "updateTime", DateTime::new,Date.class);
        strictInsertFill(metaObject, "delFlag",()->0,Integer.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        strictInsertFill(metaObject,"updateTime",Date::new,Date.class);
    }
}
